/**
 * 底部导航管理初始化
 */
var TNavList = {
    id: "TNavListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TNavList.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '序号', field: 'seq', visible: true, align: 'center', valign: 'middle'},
            {title: '图标', field: 'imageSrc', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {
          	  var e = '<img src='+row.imageSrc+' width=\'32px\' height=\"32px\">';
        	  return e;
            }},
            {title: '选中图标', field: 'selImageSrc', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {
            	  var e = '<img src='+row.selImageSrc+' width=\'32px\' height=\"32px\">';
          	  return e;
              }},
            {title: '跳转类型', field: 'jumpType', visible: true, align: 'center', valign: 'middle'},
            {title: 'appid', field: 'appId', visible: true, align: 'center', valign: 'middle'},
            {title: 'app跳转路径', field: 'appUrl', visible: true, align: 'center', valign: 'middle'},
            {title: '页面路径', field: 'pageUrl', visible: true, align: 'center', valign: 'middle'},
            {title: 'h5路径', field: 'h5Url', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
TNavList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TNavList.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加底部导航
 */
TNavList.openAddTNavList = function () {
    var index = layer.open({
        type: 2,
        title: '添加底部导航',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tNavList/tNavList_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看底部导航详情
 */
TNavList.openTNavListDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '底部导航详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tNavList/tNavList_update/' + TNavList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除底部导航
 */
TNavList.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/tNavList/delete", function (data) {
            Feng.success("删除成功!");
            TNavList.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tNavListId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询底部导航列表
 */
TNavList.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    TNavList.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TNavList.initColumn();
    var table = new BSTable(TNavList.id, "/tNavList/list", defaultColunms);
    table.setPaginationType("client");
    var appid = localStorage.getItem("appid");//获取存储的变量key的值 
    var params={"appid":appid};
    table.setQueryParams(params);
    TNavList.table = table.init();
});
